
# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
# 
# http://www.rstudio.com/shiny/
#

# input 209 BDE's molecular descriptors, scale and remove the variance-zero variables. 
# the db5ms retention time data comes from Wei's paper.

pre <- read.table('./data/predatabase')
datadb5ms <- data.frame(BDE=c(1,2,3,10,9,14,4,7,6,11,8,12,5,13,15,30,27,19,18,34,32,23,26,29,17,36,25,31,39,16,33,28,38,21,35,20,37,22,54,53,73,69,50,52,72,62,75,51,80,49,43,68,48,71,46,57,67,47,44,70,63,74,76,58,79,61,66,42,78,41,55,81,56,40,77,60,104,103,121,94,102,100,92,109,101,111,98,119,120,108,88,125,90,99,116,115,124,89,127,83,118,97,86,87,107,123,106,85,155,114,126,122,82,105,148,154,150,145,144,161,168,136,133,146,153,143,139,140,141,158,131,160,159,142,162,167,137,130,138,166,129,156,169,188,157,184,178,128,175,183,176,182,186,185,192,193,191,172,180,181,177,171,173,190,189,170,202,201,204,197,198,203,196,205,194,195,208,207,206,209),RRT=c(0.1377,0.1423,0.1471,0.199,0.2123,0.2156,0.2170,0.2183,0.2199,0.2281,0.2284,0.2335,0.2335,0.2355,0.2428,0.2757,0.2889,0.2891,0.2971,0.2984,0.3011,0.3029,0.3032,0.3032,0.3075,0.3086,0.3108,0.3136,0.3177,0.3202,0.3201,0.3212,0.3234,0.3278,0.3292,0.3291,0.3380,0.3380,0.3549,0.3622,0.3646,0.3654,0.3662,0.3754,0.3788,0.378,0.3793,0.3803,0.3851,0.3865,0.3862,0.3874,0.3872,0.3888,0.3887,0.3921,0.393,0.398,0.4018,0.4019,0.4036,0.4045,0.405,0.4072,0.4073,0.4088,0.4104,0.4104,0.4151,0.4155,0.4183,0.4249,0.4288,0.4288,0.4289,0.4297,0.4310,0.4337,0.436,0.4484,0.449,0.4539,0.4589,0.4589,0.4602,0.4618,0.4615,0.4616,0.4632,0.4625,0.4638,0.467,0.4709,0.4723,0.4766,0.4776,0.4801,0.4841,0.4862,0.486,0.4873,0.4873,0.4873,0.4883,0.4889,0.4895,0.4926,0.5009,0.5023,0.5049,0.5089,0.509,0.5128,0.5129,0.515,0.5161,0.5161,0.5223,0.5243,0.527,0.5337,0.5369,0.5370,0.5387,0.5403,0.5444,0.5465,0.5524,0.5539,0.5534,0.5534,0.5545,0.5564,0.5564,0.5579,0.5595,0.5667,0.5673,0.5689,0.5707,0.5812,0.5813,0.582,0.5826,0.5854,0.5892,0.5959,0.5979,0.6008,0.6020,0.6019,0.6064,0.6076,0.6101,0.613,0.6149,0.6195,0.6269,0.6287,0.6341,0.635,0.6398,0.6404,0.6403,0.6476,0.6578,0.6593,0.6658,0.6705,0.672,0.6822,0.6833,0.6876,0.7012,0.7144,0.7271,0.7573,0.7669,0.7929,0.9422))

shinyServer(function(input, output) {
  # print('1')
  output$text <- renderText({
    args <- switch(input$var,
                   "Stepwise" = pre[input$index,1],
                   "SVM" = pre[input$index,6],
                   "Lasso" = pre[input$index,3],
                   "Rigid regression" = pre[input$index,2],
                   "Principal components regression" = pre[input$index,4],
                   "Partial least squares regression" = pre[input$index,5])
    
    argss <- round((0.4723-(0.6020+0.3980)*args)/(0.4723-0.3980),4)
    
    argswei <- round((0.4723-(0.6020+0.3980)*ifelse(input$index %in% datadb5ms$BDE,datadb5ms[datadb5ms[,1]==input$index,2],NA))/(0.4723-0.3980),4)
    
    paste("The RRT of BDE-",input$index," is ",argss," and in Wei's paper is ",argswei)
    
  })
})
